#include "save.h"
#include "ui_save.h"

Save::Save(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Save)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::Window);

    //设置背景图片
    QPalette palette = this->palette();
    palette.setBrush(this->backgroundRole(),QBrush(QPixmap(":/resources/bluecar.jpg")));
    this->setPalette(palette);
}

Save::~Save()
{
    delete ui;
}

/**
 * @brief 显示保存面板
 *
 */
void Save::saveShow()
{
    QString score = QString::number(StatusValue::MyScore);
    ui->label_2->setText("当前成绩为: " + score);

    UsersDB *userdb = new UsersDB;
    UserModel model = userdb->getUserInfo();
    int fontsize = userdb->getFontSize(model.name);
    //设置事例字体点阵
    QFont font;
    font.setPointSize(fontsize);

    StatusValue::status = Ready;

    this->ui->label->setFont(font);
    this->ui->label_2->setFont(font);
    this->show();
}

/**
 * @brief 返回到开始面板
 *
 */
void Save::on_pushButton_2_clicked()
{
    this->hide();
    emit enterBegin();
}

/**
 * @brief 保存成绩
 *
 */
void Save::on_pushButton_clicked()
{
    QString score = QString::number(StatusValue::MyScore);
    RankDB *rankdb = new RankDB;
    rankdb->saveScore(score);

    this->hide();
    emit enterBegin();
}
